#include <fstream>
#include <iostream>
#include "Texture.h"


using namespace std;


Texture::Texture(std::string fileName)
{
	lireFichier(fileName);
	transparence = NULL;
}


void Texture::lireFichier(std::string fileName)
{
	Image tmp;
	image = tmp.lireFichier(fileName.c_str());
}

Couleur Texture::getCouleur(float x, float y)
{
	if(x<0)
		x=0;
	else if(x>1)
		x = 1;
	if(y<0)
		y=0;
	else if(y>1)
		y=1;

	int img_x = (int)(x*image->w_);
	int img_y = (int)(y*image->h_);
		// on cherche le pixel qui correspond
	return Couleur((float)image->pic[img_x * 3 + img_y * image->w_ * 3]/255,
		(float)image->pic[img_x * 3 + img_y * image->w_ * 3 + 1]/255, 
		(float)image->pic[img_x * 3 + img_y * image->w_ * 3 + 2]/255 );
}